package com.dci.service.impl.schedule;

import com.dci.context.Config;
import com.dci.dao.pms.project.PmsItemInputMapper;
import com.dci.dao.pms.schedule.PmsCapitalContractMapper;
import com.dci.model.project.PmsItemInput;
import com.dci.model.schedule.PmsCapitalContract;
import com.dci.result.ResultInfo;
import com.dci.result.ResultUtil;
import com.dci.service.schedule.PmsCapitalContractService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PmsCapitalContractServiceImpl implements PmsCapitalContractService {

    @Resource
    private PmsCapitalContractMapper pmsCapitalContractMapper;

    @Resource
    private PmsItemInputMapper pmsItemInputMapper;

    /**
     * 添加合同
     *
     * @param pmsCapitalContract
     * @return
     */
    @Override
    public ResultInfo addContract(PmsCapitalContract pmsCapitalContract) {
        int i = pmsCapitalContractMapper.addContract(pmsCapitalContract);
        if (i > 0) {
            return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
        } else {
            return ResultUtil.createSuccess(Config.MESSAGE, 911, null);
        }
    }

    /**
     * 修改合同
     *
     * @param pmsCapitalContract
     * @return
     */
    @Override
    public ResultInfo updateContract(PmsCapitalContract pmsCapitalContract) {
        int i = pmsCapitalContractMapper.updateContract(pmsCapitalContract);
        if (i > 0) {
            return ResultUtil.createSuccess(Config.MESSAGE, 906, null);
        } else {
            return ResultUtil.createSuccess(Config.MESSAGE, 911, null);
        }
    }

    /**
     * 通过id查询信息
     *
     * @param capitalId
     * @return
     */
    @Override
    public List<PmsCapitalContract> selectContractById(String capitalId) {
        List<PmsCapitalContract> list = pmsCapitalContractMapper.selectContractById(capitalId);
        if (list.size() > 0) {
            for (PmsCapitalContract pmsCapitalContract : list) {
                List<PmsItemInput> list1 = pmsItemInputMapper.selectByContractId(pmsCapitalContract.getId());
                pmsCapitalContract.setList(list1);
            }
        }
        return list;
    }
}
